package com.websuites.esb.cluster;

import java.util.ArrayList;
import java.util.List;

import org.jgroups.Address;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;

import org.jgroups.View;

import com.websuites.utils.LogUtil;

public class ProxyReceiverAdapter extends ReceiverAdapter
{
	private Address address;
	private List<Receiver> listReceiver = new ArrayList<Receiver>();
	
    public ProxyReceiverAdapter() {}
    
    public void setAddress(Address address)
    {
    	this.address = address;
    }
        
    public void receive(Message msg) 
    {  
    	if (msg.getSrc() == this.address)
    	{
    		return;
    	}
    	try 
    	{ 
    		for (int i = 0; i < listReceiver.size(); i++)
    		{
    			Receiver receiver = listReceiver.get(i);
        		receiver.receive(msg);
    		}
    	} 
    	catch (Exception e)
        {
    		e.printStackTrace();
        }    
    }

	public void viewAccepted(View view) 
	{
		LogUtil.info("view = " + view);
	}

    public void suspect(Address suspected_mbr)
    {
    	LogUtil.info("suspected_mbr = " + suspected_mbr);
    }

    public void registerReceiver(Receiver receiver) 
    {  
    	listReceiver.add(receiver);
    }

}
